from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `good` ADD `cid_two_id` INT   COMMENT '所属二级分类id';
        ALTER TABLE `good` ADD `cid_one_id` INT   COMMENT '所属一级分类id';
        ALTER TABLE `good` ADD `cid_three_id` INT   COMMENT '所属三级分类id';
        ALTER TABLE `good` ADD CONSTRAINT `fk_good_category_c03e4b27` FOREIGN KEY (`cid_one_id`) REFERENCES `category` (`id`) ON DELETE CASCADE;
        ALTER TABLE `good` ADD CONSTRAINT `fk_good_category_95b6c021` FOREIGN KEY (`cid_two_id`) REFERENCES `category` (`id`) ON DELETE CASCADE;
        ALTER TABLE `good` ADD CONSTRAINT `fk_good_category_5f9a2b2f` FOREIGN KEY (`cid_three_id`) REFERENCES `category` (`id`) ON DELETE CASCADE;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `good` DROP FOREIGN KEY `fk_good_category_5f9a2b2f`;
        ALTER TABLE `good` DROP FOREIGN KEY `fk_good_category_95b6c021`;
        ALTER TABLE `good` DROP FOREIGN KEY `fk_good_category_c03e4b27`;
        ALTER TABLE `good` DROP COLUMN `cid_two_id`;
        ALTER TABLE `good` DROP COLUMN `cid_one_id`;
        ALTER TABLE `good` DROP COLUMN `cid_three_id`;"""
